package io.cici.cc.mybatis.plus.core.incrementer;

import io.cici.cc.mybatis.plus.core.toolkit.Sequence;

import java.net.InetAddress;

/**
 * 默认生成器
 */
public class DefaultIdGenerator implements IdGenerator {

    private final Sequence sequence;

    /**
     * @see #getInstance()
     * @deprecated 3.5.3.2 共享默认单例
     */
    @Deprecated
    public DefaultIdGenerator() {
        this.sequence = new Sequence(null);
    }

    public DefaultIdGenerator(InetAddress inetAddress) {
        this.sequence = new Sequence(inetAddress);
    }

    public DefaultIdGenerator(long workerId, long dataCenterId) {
        this.sequence = new Sequence(workerId, dataCenterId);
    }

    public DefaultIdGenerator(Sequence sequence) {
        this.sequence = sequence;
    }

    public static DefaultIdGenerator getInstance() {
        return DefaultInstance.INSTANCE;
    }

    @Override
    public Long nextId(Object entity) {
        return sequence.nextId();
    }

    private static class DefaultInstance {

        public static final DefaultIdGenerator INSTANCE = new DefaultIdGenerator();

    }

}
